package com.tuananh.radnom.persist;

import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.jms.connection.CachingConnectionFactory;


@Configuration
public class JmsConfiguration {
    @Bean(name = "connectionFactory")
    public ConnectionFactory getConnectionFactory() {
        ActiveMQConnectionFactory targetConnectionFactory = new ActiveMQConnectionFactory();
        targetConnectionFactory.setUserName("admin");
        targetConnectionFactory.setPassword("activemq");
        CachingConnectionFactory connectionFactory =
                new CachingConnectionFactory(targetConnectionFactory);
        connectionFactory.setSessionCacheSize(10);
        connectionFactory.setCacheProducers(false);
        connectionFactory.setClientId("TuanAnh207");

        return connectionFactory;
    }

    @Bean
    public ActiveMQTopic eventTopic() {
        ActiveMQTopic activeMQTopic = new ActiveMQTopic("radnom.event");
        return activeMQTopic;
    }

    @Bean
    public MessageChannel eventChannel() {
        MessageChannel channel = new DirectChannel();
        return channel;
    }

}
